<template>
  <div :id="id" :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    id: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "200px",
    },
    height: {
      type: String,
      default: "200px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  created() {},
  mounted() {
    this.initChart();
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      var data1 = [20, 30, 40, 50];
      var data2 = [30, 30, 9, 60];
      var data3 = [20, 30, 20, 30];
      var data4 = [20, 30, 40, 50];
      var datacity = ["安徽理工大学", "安徽新华学院", "安徽国际商务职业学院"];
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption({
        color: ["#3091F2", "#FF8B17", "#2945CB", "#31C670"],
        tooltip: {
          trigger: "axis",
        },
        title: {
          text: "订单周期产能占比图",
          textStyle: {
            fontWeight: "800",
            fontSize: 18,
            color: "#363B48",
          },
          left: "0",
        },
        legend: {
          right: 20,
          top: 0,
          itemGap: 10, // 各个item之间的间隔，单位px，默认为10，
          itemWidth: 12, // 图例图形宽度
          itemHeight: 12,
          textStyle: {
            color: "#8FA1C9",
            fontWeight: "normal",
            fontSize: 16,
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "30",
          containLabel: true,
        },
        yAxis: [
          {
            type: "value",
            min: 0,
            max: 100,
            splitNumber: 5,
            splitLine: { show: false },
            axisLabel: {
              //坐标轴刻度标签的相关设置。
              show: true,
              textStyle: {
                color: "#A5B2CC",
              },
            },
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              lineStyle: {
                color: "rgba(131,101,101,0.2)",
              },
            },
            show: true,
          },
        ],
        xAxis: [
          {
            type: "category",
            axisTick: {
              show: false, // 是否显示坐标轴轴线
            },
            axisLabel: {
              color: "#A5B2CC",
            },
            splitLine: {
              show: false,
            },
            boundaryGap: true,
            axisLine: {
              //坐标轴轴线相关设置。
              show: true,
              inside: false,
              lineStyle: {
                color: "#EBEDF2",
              },
            },

            data: datacity,
          },
        ],
        series: [
          {
            name: "预排产量(自工厂)",
            type: "bar",
            stack: "sum",
            barWidth: "16px",
            data: data1,
          },
          {
            name: "预排产量(外协厂)",
            type: "bar",
            barWidth: "16px",
            stack: "sum",
            data: data2,
          },
          {
            name: "ERP订单冲销量",
            type: "bar",
            stack: "sum1",
            barWidth: "16px",
            data: data3,
          },
          {
            name: "月计划实际达成量",
            type: "line",
            data: data4,
            smooth: true,
            showSymbol: false,
          },
        ],
      });
    },
  },
};
</script>

<style scoped lang="less"></style>
